﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeavenCommon.DataMap;

namespace FortuneHeavenDAL
{
    public class LotteryOrderDAL : BaseDAL
    {
        public List<LotteryOrder> GetTopList(int top)
        {
            string sql = @"Select TOP " + top + @" * from LotteryOrder ORDER BY  RequestTime DESC";
            return dbOper.Query<LotteryOrder>(sql);
        }

        public int GetTotalCount()
        {
            string sql = @"Select count(ID) from LotteryOrder";
            return dbOper.GetScalar<int>(sql);
        }


        public List<LotteryOrder>  GetLotteryOrderList(int page, int size, string acount)
        {
            if (string.IsNullOrEmpty(acount) || acount.Trim() == "")
            {
                string sql = @"SELECT * FROM 
(select (Select count(ID) from LotteryOrder where UserID=A.UserID) as LotteryCount ,B.OnLineTimeCount as OnLineTimeCount,A.* ,ROW_NUMBER() OVER(ORDER BY A.RequestTime DESC) ROW  
from LotteryOrder  A Left join QPTreasureDB..GameScoreInfo B on A.UserID= B.UserID
 ) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
                List<LotteryOrder> list = dbOper.Query<LotteryOrder>(sql, size * (page - 1) + 1, size * page);
                return list;
            }
            else
            {
                string sql = @"SELECT * FROM 
(select (Select count(ID) from LotteryOrder where UserID=A.UserID) as LotteryCount ,B.OnLineTimeCount as OnLineTimeCount,A.* ,ROW_NUMBER() OVER(ORDER BY A.RequestTime DESC) ROW  
from LotteryOrder  A Left join QPTreasureDB..GameScoreInfo B on A.UserID= B.UserID WHERE A.UserName= @P0
 ) FF
 WHERE FF.ROW BETWEEN  @p1 AND @p2";
                List<LotteryOrder> list = dbOper.Query<LotteryOrder>(sql, acount, size * (page - 1) + 1, size * page);
                return list;
            }
        }
        public int GetTotalSize(string acount)
        {
            if (!string.IsNullOrEmpty(acount) && acount.Trim() != "")
            {
                string sql = @"select count(id) from LotteryOrder where UserName =@p0";
                return dbOper.GetScalar<int>(sql, acount);
            }
            else
            {
                string sql = @"select count(id) from LotteryOrder";
                return dbOper.GetScalar<int>(sql);
            }
        }
        public void AuditItems(string ids, int auditid,string auditname,DateTime time)
        {
            string sql = "update LotteryOrder set Status =1,AuditID =@p0,AuditName=@p1,AuditTime =@p2 where ID in({0})";
            dbOper.RunSql(string.Format(sql,ids), auditid,auditname,time);
        }

    }
}
